import React from 'react';
import { Link, useLocation } from 'react-router-dom';
import qs from 'qs';
import { Pagination } from 'antd';

function IndexPagination () {
  let { search } = useLocation();
  let { tab = "all", page = 1 } = qs.parse(search.substr(1));
  return (<div className="index_pagination">
    <Pagination
      current={page - 0}
      total={1000}
      pageSize={20}
      itemRender={((page, type) => {
        switch (type) {
          case 'prev':
            return <Link to={`/?tab=${tab}&page=${page}`}>{`<`}</Link>
          case 'next':
            return <Link to={`/?tab=${tab}&page=${page}`}>{`>`}</Link>
          case 'page':
            return <Link to={`/?tab=${tab}&page=${page}`}>{page}</Link>
          default:
            return <Link to={`/?tab=${tab}&page=${page}`}>{`…`}</Link>
        }
      })}
    />
  </div>)
};

export default IndexPagination;
